<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib  prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib  prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="redis" uri="http://www.shopjsp.com/redisTag/functions" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${redis:getSysConfig('base_path_back')}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>粉丝用户信息</title>
        <jsp:include page="../../util/import.jsp"/>
        <script type="text/javascript">
            /**
             * 初始化分类Table
             */
            $(function(){
                var $tt= $("#tt").bootstrapTable({
                    url: '${basePath}/back/wx/fansUserInfo/listFansUserInfo.sjson ',        	/**请求后台的URL（*）**/
                    method: 'post',                       	/**请求方式（*）**/
                    contentType: "application/x-www-form-urlencoded",
                    dataType: 'json',
                    toolbar: '#toolbar',               	    /**工具按钮用哪个容器**/
                    striped: true,                      	/**是否显示行间隔色**/
                    cache: false,                       	/**是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）**/
                    pagination: true,                   	/**是否显示分页（*）**/
                    sortable: false,                    	/**是否启用排序**/
                    sortOrder: 'asc',                   	/**排序方式**/
                    queryParamsType: '',
                    sidePagination: 'server',           	/**分页方式：client客户端分页，server服务端分页（*）**/
                    pageNumber: 1,
                    pageSize:10,							/**初始化加载第一页，默认第一页**/
                    pageList: [5,10, 25, 50],        	    /**可供选择的每页的行数（*）**/
                    search: false,                       	/**是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大**/
                    strictSearch: true,
                    showColumns: true,                  	/**是否显示所有的列**/
                    showRefresh: true,                  	/**是否显示刷新按钮**/
                    minimumCountColumns: 2,             	/**最少允许的列数**/
                    clickToSelect: true,                	/**是否启用点击选中行**/
                    uniqueId: 'userId',                     /**每一行的唯一标识，一般为主键列**/
                    singleSelect  : true,                   /** 单选checkbox**/
                    showToggle:false,                    	/**是否显示详细视图和列表视图的切换按钮**/
                    cardView: false,                    	/**是否显示详细视图**/
                    detailView: false,                  	/**是否显示父子表**/
                    columns: [
                        {checkbox: true},
                        {field: 'Number', title: '编号',align: 'center',valign: 'middle',width:'50px',
                            formatter: function (value, row, index) {
                                var page = $tt.bootstrapTable("getPage");
                                return page.pageSize * (page.pageNumber - 1) + index + 1;
                            }
                        },
                        {field: 'nickName',title: '昵称',align: 'center',valign: 'middle',
                            formatter: function (value, row, index) {
                                var a_html = '<a data-toggle="modal" data-target="#detailModal" href="#" mce_href="#" onclick="detailInfo(' + row.userId + ')">' + value + '</a>';
                                return a_html;
                            }
                        },
                        {field:"loginName",title:"会员名称",align: 'center',valign: 'middle',
                            formatter: function (value, row, index) {
                                if(value==""||value==undefined){
                                    return "";
                                }else {
                                    var a_html = '<a data-toggle="modal" data-target="#customerDetailModal" href="#" mce_href="#" onclick="customerDetailInfo(' + row.customerId + ')">' + value + '</a>';
                                    return a_html;
                                }
                            }
                        },
                        {field:"plateFormRemark",title:"名称备注",align: 'center',valign: 'middle',
                            formatter:function (value,row,index) {
                                if(value==""||value==undefined){
                                    return "";
                                }else{
                                    return value;
                                }
                            }
                        },
                        {field:"sex",title:"性别",align: 'center',valign: 'middle',
                            formatter:function (value,row,index) {
                                if(value=="2"){
                                    return "女";
                                }else if(value=="1"){
                                    return "男";
                                }else{
                                    return "";
                                }
                            }
                        },
                        {field:"customerAddress",title:"会员地址",align: 'center',valign: 'middle',
                            formatter:function (value,row,index) {
                                var customerAddress="";
                                if (row.userCountry!=""&&row.userCountry!=undefined){
                                    customerAddress+=row.userCountry;
                                    if (row.userProvince!=""&&row.userProvince!=undefined){
                                        customerAddress+="-"+row.userProvince;
                                        if (row.userCity!=""&&row.userCity!=undefined){
                                            customerAddress+="-"+row.userCity;
                                            return customerAddress;
                                        }
                                        return customerAddress;
                                    }
                                    return customerAddress;
                                } else{
                                    return customerAddress;
                                }
                            }
                        },
                        {field:"fansGroupId",title:"所在分组",align: 'center',valign: 'middle',
                            formatter:function (value,row,index) {
                                var name="";
                                <c:forEach items="${wxFansGroupList}" var="kb">
                                if(value=="${kb.fansGroupId}"){
                                    name= "${kb.name}";
                                }
                                </c:forEach>
                                if(""!=name){
                                    return name;
                                }else{
                                    return "未分组";
                                }
                            }
                        },
                        {field:"subscribe",title:"是否关注",align: 'center',valign: 'middle',
                            formatter:function (value,row,index) {
                                if(value==0){
                                    return "<font class='color_002'>否</font>";
                                }else if(value==1){
                                    return "<font class='color_001'>是</font>";
                                }
                            }
                        },
                        {field:"subscribeTime",title:"关注时间",align: 'center',valign: 'middle',
                            formatter:function (value,row,index) {
                                if(value!=""&&value!=undefined){
                                    return toJsonDate(value,"yyyy-MM-dd hh:mm:ss");
                                }else {
                                    return "";
                                }
                            }
                        }
                    ],
                    queryParams: function (params) {
                        /**特别说明，返回的参数的值为空，则当前参数不会发送到服务器端,这种指定请求参数的方式和datatables控价类似**/
                        params.loginName = $("#q_loginName").val();
                        params.plateFormRemark = $("#q_plateFormRemark").val();
                        params.subscribe = $("#q_subscribe").val();
                        params.subscribeBeginTime = $("#q_subscribeBeginTime").val();
                        params.subscribeEndTime = $("#q_subscribeEndTime").val();
                        params.fansGroupId = $("#q_fansGroupId").val();
                        params.currentPage = params.pageNumber;
                        return params;
                    }
                });
            });

            /**
             * 删除粉丝分组
             */
            <shiro:hasPermission name="back_gotoFansUserInfoPage_delete">
            function deleteInfo(){
                /**获取选中行的id**/
                var selectedRow= $("#tt").bootstrapTable('getSelections');
                if(selectedRow.length==1){
                    var id=selectedRow[0].userId;
                    showConfirm("你确定要删除吗?", function() {
                        $.ajax({
                            type: "POST",
                            dataType: "JSON",
                            url: "${basePath}/back/wx/fansUserInfo/deleteFansUserInfo.sjson",
                            data: {userId:id},
                            success: function(data){
                                if(data.success==true){
                                    $("#tt").bootstrapTable('refresh');
                                }
                            }
                        });
                    });
                }else{
                    showMsg("请选择一行记录！");
                }
            }
            </shiro:hasPermission>
        </script>
    </head>

    <body>
        <div class="panel-body" id="customer-main-panel">
            <!-- 查询条件 -->
            <div class="panel panel-default">
                <div class="panel-heading">粉丝用户信息查询</div>
                <div class="panel-body">
                    <form id="qform" class="form-horizontal">
                        <div class="form-group" style="margin-top:15px">
                            <div class="col-sm-2">
                                <div class="input-group input-group-sm">
                                    <span class="input-group-addon">会员名称</span>
                                    <input type="text" class="form-control" id="q_loginName" name="loginName" placeholder="请输入会员名称"/>
                                </div>
                            </div>
                            <div class="col-sm-2">
                                <div class="input-group input-group-sm">
                                    <span class="input-group-addon">名称备注</span>
                                    <input type="text" class="form-control" id="q_plateFormRemark" name="plateFormRemark" placeholder="请输入名称备注"/>
                                </div>
                            </div>
                            <div class="col-sm-2">
                                <div class="input-group input-group-sm">
                                    <span class="input-group-addon">是否关注</span>
                                    <select id="q_subscribe" class="form-control">
                                        <option value="">请选择</option>
                                        <option value="0">否</option>
                                        <option value="1">是</option>
                                    </select>
                                </div>
                            </div>
                            <div class="col-sm-2">
                                <div class="input-group input-group-sm">
                                    <span class="input-group-addon">组别</span>
                                    <select id="q_fansGroupId" class="form-control">
                                        <option value="">----全部----</option>
                                        <c:forEach items="${wxFansGroupList}" var="kb">
                                            <option value="${kb.fansGroupId}">${kb.name}</option>
                                        </c:forEach>
                                    </select>
                                </div>
                            </div>
                            <div class="col-sm-3"  style="width: 320px;">
                                <div class="input-group input-group-sm ">
                                    <span class="input-group-addon">关注开始时间</span>
                                    <div class="input-group date form_datetime" data-link-field="dtp_input1">
                                        <input id="q_subscribeBeginTime" name="subscribeBeginTime" style="height: 30px; border: 1px solid #c6c6c6;border-right:none;padding-left:10px; " size="13" type="text" value=""  placeholder="请选择开始时间" readonly>
                                        <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
                                        <span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
                                    </div>
                                    <script type="text/javascript">
                                        $('.form_datetime').datetimepicker({format: "yyyy-MM-dd",language:'zh-CN',weekStart:1, todayBtn:1,autoclose: 1,todayHighlight: 1,startView: 2, minView: 2, forceParse: 0});
                                    </script>
                                </div>
                            </div>
                            <div class="col-sm-3" style="width: 320px;">
                                <div class="input-group input-group-sm ">
                                    <span class="input-group-addon">关注结束时间</span>
                                    <div class="input-group date form_datetime" data-link-field="dtp_input1">
                                        <input id="q_subscribeEndTime" name="subscribeEndTime" style="height: 30px; border: 1px solid #c6c6c6;border-right:none;padding-left:10px; " size="13" type="text" value=""  placeholder="请选择结束时间" readonly>
                                        <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
                                        <span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
                                    </div>
                                    <script type="text/javascript">
                                        $('.form_datetime').datetimepicker({format: "yyyy-MM-dd",language:'zh-CN',weekStart:1, todayBtn:1,autoclose: 1,todayHighlight: 1,startView: 2, minView: 2, forceParse: 0});
                                    </script>
                                </div>
                            </div>
                            <div class="col-sm-2" style="width: 140px;">
                                <button type="button" id="btn_query" class="btn btn-primary">查询</button>
                                <button type="reset" class="btn btn-success" id="resetBtn">重置</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

            <!-- 工具栏 -->
            <div id="toolbar" class="btn-group">
                <shiro:hasPermission name="back_gotoFansUserInfoPage_delete">
                    <button id="btn_delete" type="button" class="btn btn-default" onclick="deleteInfo()">
                        <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除
                    </button>
                </shiro:hasPermission>
                <shiro:hasPermission name="back_gotoFansUserInfoPage_groupNoRelation">
                    <button id="btn_manageGroups" type="button" class="btn btn-default" data-toggle="modal" onclick="manageGroups()">
                        <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>管理分组
                    </button>
                </shiro:hasPermission>
                <shiro:hasPermission name="back_gotoFansUserInfoPage_remark">
                    <button id="btn_change" type="button" class="btn btn-default" data-toggle="modal" onclick="changePlateFormRemark()">
                        <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>修改名称备注
                    </button>
                </shiro:hasPermission>
                <%--暂时不做--%>
                <%--<button id="btn_getAllFans" type="button" class="btn btn-default" data-toggle="modal" onclick="">
                    <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>获取粉丝列表
                </button>
                <button id="btn_getSingleFans" type="button" class="btn btn-default" data-toggle="modal" onclick="">
                    <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>获取单个粉丝信息
                </button>--%>
            </div>

            <!-- 渲染的table -->
            <table id="tt"></table>

            <!-- 详情页面 -->
            <jsp:include page="detail.jsp"/>
            <!-- 会员详情页面 -->
            <jsp:include page="customerDetail.jsp"/>
            <!-- 管理分组页面 -->
            <jsp:include page="manageGroups.jsp"/>
            <!-- 修改名称备注页面 -->
            <jsp:include page="changePlateFormRemark.jsp"/>
        </div>
    </body>
</html>
